Jscolor stops working after first postback of fresh deploy, but continues to work after postback of a reload

StackOverflow https://stackoverflow.com/questions/16941906

  •  31-05-2022
  •  | 
  •  

Question

Could anyone tell me something helpful to the following behavior in JSF with Jscolor component?

I have got this simple xhtml code:

<?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html">
        <h:head>
            <title>RDFa test</title>
        </h:head>
        <h:body>    
            <script type="text/javascript" src="resources/js/jscolor/jscolor.js"/>
            <h:form>
                <h:commandButton class="color" value="ok"/>
                <h:commandButton value="server" type="submit" action="#{testBean.tmp}"/>
            </h:form>
        </h:body>
    </html>

TestBean.java:

@ManagedBean
@SessionScoped
public class TestBean implements Serializable {
    public TestBean() {}

    public void tmp() {
        System.out.println("SERVER!");
    }   
}

If I do the first deployment and click on the "server" button, the Jscolor will go away and does not work (it is like destroying the javascript on the page)! If I then reload the page and click on the same button, the Jscolor works normally. There's no exception in server log, nor any error in Firebug JS console. How is this caused and how can I solve it?

EDIT: I am not the only developer, who straggles with this issue. Here tyhand describes exactly, what I mean: http://www.tek-tips.com/viewthread.cfm?qid=1641380

COuld you please explain me what is happening and how to solve it?

Était-ce utile?

La solution

Finally I found a solution. It is so easy!!! I have to add before all input fields with class='color' (binding fileds to the jscolor) this code:

<script>jscolor.init();</script>

Autres conseils

I wanted to use jscolor inside a repeater that was inside an update panel in a custom DNN module.

None of the various solutions I saw here worked...I finally figured it out.

At top of HTML in your usercontrol: Use <dnn:DNNJsInclude..... /> to point to your jscolor.js file, then add

<script type="text/javascript">


function pageLoad(sender, args) {

    $(".jscolor").each(function (i, obj) {

        var picker = new jscolor(obj);

    });
};

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top