ColorPicker on jsf page - java

I need color picker on my page.
First, I placed Primefaces' colorpicker, but when I tried to use it, I received "IllegalArgumentException: text/xml is not a supported mime type". Probably this occurs because I use my own jquery library, which has no colorpicker element, and it overrides Primefaces' one.
So, I tried it in other way. I used "jscolor" library which turns any input field to colorpicker. I got component:
<h:inputText value="#{searchManagedBean.selectedColor}" class="color"/>
It works perfectly, but when I submit form, value in backing bean doesn't update. In backing bean I have getter and setter for this field, so I can't figure out what is the reason of this problem.
Could you help me with one of these problems, or maybe provide another solution?
Thanks!

I found the solution. If I update the value in some other element, value in backing bean updates too. So, now I have something like this:
<h:inputText value="#{searchManagedBean.selectedColor}" class="color">
<p:ajax event="change" update="outcolor"/>
</h:inputText>
<h:outputText style="display: none" id="outcolor" value="#searchManagedBean.selectedColor}"/>
For me, it's very strange behaviour. I don't know why it works, but it works!

Related

How to solve encoding problems when using strange characters of titles in JSF and Primefaces

I am in trouble with encoding values. Well I am developing a web page with spanish content, and it uses tittles like ó,á,è, etc, or characters like ñ. Then when I pressed the button to save the values, I guess the ajax event for a button didn't take the encodig, them I add encoding='ISO-8859-1', and it worked. But I have an autocomplete for countries in primefaces that also use an ajax event to proccess information, and for this field the encoding doesn't work and before to add encoding='ISO-8859-1' it worked. Well when solve one, the other one failed, and vice versa.
Happen that I need the country to consult the states and list them.
Web code:
<p:autoComplete id="pais" value="#{personal.pais}"
completeMethod="#{personal.listPaises}" forceSelection="true" required="true" effect="fade" scrollHeight="400"
var="p" itemLabel="#{p}" itemValue="#{p}" requiredMessage="Es necesario seleccionar país" label="País" validator="#{personal.validatePaises}" >
<p:column style="width:80%" >
#{p}
</p:column>
<p:ajax event="itemSelect" update="departamento" />
</p:autoComplete>
Java Code:
public void setPais(String pais) {
int codPais = pDao.getPaisCod(pais);
departamentosList = pDao.listDepatamentosByPais(codPais);
this.pais = pais;
}
For example if I choose España as Country in jsf form, in the bean is taken as Espa±a.
I need unify the encodig.
Thanks a lot.
You should just use UTF-8, it will support any character and more importantly it is the only encoding that everything has in common. Often something will only work with UTF-8, such as many JSON implementations. And when that isn't the case, JSON cannot support ISO-8859-1 anyways.
For instance, primeface's Ajax uses jQuery.param, which uses encodeURIComponent, which uses URL encoding that is based on UTF-8.
So if you want to unify encoding, UTF-8 is your only option.
Btw, by "use UTF-8", I don't mean just to put UTF-8 in a random place that seems right but actually ensure UTF-8 is the declared and physical encoding everywhere in your project.
I know that my problem was with ajax request of autocomplete and commandButton.Then I tried everything and didn't work. well I solve my problem changing my jsf commandButton to Primefaces commandButton.
Before
<h:commandButton value="submit" action="Periodico?faces-redirect=true" actionListener="#{personal.insertarUsuario}" />
After
<p:commandButton value="submit" action="Periodico?faces-redirect=true" actionListener="#{personal.insertarUsuario}" />
And so I solve my problem. Thanks a lot for your time and answers

#all in JSF Ajax does not work

This line is inside a form tag:
<p:commandLink actionListener="#{questionBean.removeQuestion(question)}"
value="Delete" styleClass="delete" update="#all"/>
However, it only works with #form. Nothing happens when I have #all. I want to be able to update not only the form but also other parts of the page.
Seems that update="#all" not supported by primefaces
although its a bit diff question update="#all" is not working with "ui:include ..."
but still its being said several time that
update="#all" does not work with PimeFaces.
another ref : Issue 2026: update="#all" is not working PrimeFaces ajax.
Try with process="#all" as explained here.
<p:commandLink actionListener="#{questionBean.removeQuestion(question)}"
value="Delete" styleClass="delete" process="#all"/>
I think it may be a bug. Even if you use JSF's <f:ajax render="#all">, it may also does not work. To solve this, I think you can simply set the id attribute of the body tag to, for example, mySexyBody. Then you can do update="mySexyBody".

No component found to process as 'ajaxSingle'

Found strange problem, possibly bug.
I have 2 identical web-pages with Richfaces:suggestionbox.
On the first one my suggestionBox is doing well, everything works fine, but on another one i have some problems. SuggestionBox doesn't show my suggestions. In logs i have something like this:
WARNING: No component found to process as 'ajaxSingle' for clientId remains-form:konta-suggest
2010.1.9 12:02:29 org.ajax4jsf.component.AjaxViewRoot processPhase
Any conclusions?
UPD:
<h:inputText value="#{repobean.kont}" id="kont" label="Payer" style="width:230px;"/>
<rich:suggestionbox onobjectchange="printObjectsSelected(#{rich:element('konta-id')}, #{rich:component('konta-suggest')}, 'id');" usingSuggestObjects="true" width="230" var="result" fetchValue="#{result.kont}" suggestionAction="#{kontabean.suggest}" id="konta-suggest" for="kont">
<h:column>
<h:outputText value="#{result.kont}"/>
</h:column>
<h:column>
<h:outputText value="#{result.kontName}"/>
</h:column>
</rich:suggestionbox>
<h:inputHidden id="konta-id" value="#{repobean.kontId}" />
Javascript inside onobjectchange is a function which prints id into konta-id.
The code of jsp on the second page is copy-pasted from the first page.
I know, the question is 5 years old, but we had this same error (with different components)
In our case we have changed the outer ui:repeat to an a4j:repeat.
After that, our components worked as expected.
What you can do, when you encounter Ajax problems, is to add the <a4j:log> component:
<a4j:log popup="false"/>
This will create a box in your page with all the Ajax logs from Richfaces. Eventually, you can set popup="true" and then display the popup by Ctrl + Shift + L
There are many logs in this panel, but generally the important things to look at is the WARN or ERROR messages.
Other concern about your error message: it is talking about some ajaxSingle processing. In your JSF code, you have no ajaxSingle attribute defined. When does this error happens? When you start typing some characters in your inputText component?
Isn't there any conditional rendering (rendered="#{some expression}") around this input and suggestion components? Or an iteration?
Does .suggest() action get invoked before this error?
Situations like you've described happen when an action-related (causing) component is within a conditional render (or an iteration) which does not allow a component to be created on RestoreView phase. Then action is not called at all and component-id is not found in the component tree.
Example: if you have something like this:
<h:panelGroup rendered="#{not empty myBean.valueSetInActionHandler}">
<h:commandLink id="action1" action="#{myBean.callOtherAction" value="appears after action"/>
</h:panelGroup>
<h:commandLink id="action2" action="#{myBean.setValueInActionHandler}" value="display button above"/>
First render - only one, second button is rendered. If setValueInActionHandler sets some value and displays the same page - first button ("appears after action") will get rendered too. But clicking it won't fire a callOtherAction - because on second request, during RestorePhase valueInActionHandler is empty again, so action1 will not be available...
Hope I managed to make myself clear :)
I think a4j taglib is missing on the page.

How to use RichFaces a4j:commandButton not using submit

I have an a4j:commandButton which looks like this
<a4j:commandButton id="stopBtn" type="button" reRender="lastOp"
action="#{MyBacking.stop}" value="Stop" />
</a4j:commandButton>
When the app is deployed, and the button clicked, the stop() method is not being called. All the a4j:commandButton examples refer to forms, but this button is not in a form - it's a button the user is going to use to cause the server to run some back-end logic. At the moment, the method is
public void stopNode() {
logger.info("STOPPING");
setLastOp("Stopped.");
}
Other methods which don't use this type of button are updating the lastOp field, but I'm not seeing anything on the console with this one. Am I right to cast this as a button? Should I put this in a h:form tag?
The firebug console says:
this._form is null
which I don't understand.
Any help well appreciated.
UICommand components ought to be placed inside an UIForm component. So, your guess
Should I put this in a h:form tag?
is entirely correct :) This because they fire a POST request and the only (normal) way for that is using a HTML <form> element whose method attribute is set to "post". Firebug also says that a parent form element is been expected, but it resolved to null and thus no actions can be taken place.
Only "plain vanilla" links like h:outputLink and consorts doesn't need a form, because they just fires a GET request.
Yes, wrap it in a form. I'm sure BalusC will post a detailed explanation while I'm typing my answer. (yup, there it is)
I have to ask why you didn't just try a form first, before posting here.
Look at your code:
<a4j:commandButton id="stopBtn" type="button" reRender="lastOp" action="#{MyBacking.stop}" value="Stop" />
You finished <a4j:commandButton with />, why need that orphan </a4j:commandButton> ?
If for some reason you don't want to place the button inside a form, you can do something like this:
<a4j:commandButton onclick="fireAjax()"/>
<h:form>
<a4j:jsFunction name="fireAjax" action=".."/>
</h:form>

Passing data from request ManagedBeans in JSF

I'm somewhat confused about the lifecycle of ManagedBeans of type "request".
In this example i'm using one request bean "userBean" to fill this page and one request bean "userEditBean" to fill the following edit page.
<h:form>
<h:panelGrid border="1" columns="2">
<h:outputText value="Name" />
<h:outputText value="#{userBean.user.name}" />
...
</h:panelGrid>
<h:commandButton value="Edit" action="edit" actionListener="#{userEditBean.init}">
<f:attribute name="user" value="#{userBean.user}"/>
</h:commandButton>
</h:form>
When i press the Edit button a userEditBean is created but the attribute map resolves "user" to null.
Does this mean that the attribute EL is resolved after the userBean has already been destroyed? How can i pass values from incoming beans to outgoing beans?
You're setting the attribute value with an expression, not a static value. Whenever you request the value, the expression will be re-evaluated again. The userBean.user apparently isn't present in the subsequent request. You need to ensure that it is there (in other words, the constructor of the userBean should ensure that the user is been created and set.
There are however alternatives. One of the best is to use Tomahawk's <t:saveState> for that. Add it somewhere in the page:
<t:saveState value="#{userBean.user}" />
That said, I agree with Bozho that the whole approach is a bit strange, but that's another story. You may however get lot of useful ideas out either of the following articles: Communication in JSF and/or Using Datatables. Good luck.
request scope means the bean lives during one request. And you fill your edit page (1st request), and send the edited user (2nd request).
In addition to that, <f:attribute> sets tha attributes in the parent component, not in the request. So in your code the attributes will be found in the button.getAttributes() (if you have bound your button).
Furthermore, it is strange to have an actionListener method named init. Since you don't need the event, you can set the action to be the method which will do the editing operation, and make that method return the navigation-rule you want.

Categories

Resources