This content has been marked as final.
Show 6 replies
-
1. Re: RequestParameter is null
tienlantri Oct 5, 2010 6:06 AM (in response to tienlantri)one remark that the delete action that I perform, is define in *<a4j:commandLink>*
<a4j:commandLink ajaxSingle="true"
action="#{gestionCodeLibelle.deleteSelectedItem}"
reRender="myTable" eventsQueue="serviceQueue">
<h:graphicImage value="/img/icones/supprimer.png" />
</a4j:commandLink> -
2. Re: RequestParameter is null
rvaneperen Oct 5, 2010 11:32 PM (in response to tienlantri)I don't see where you're passing the parameter with your a4j:commandLink. I think you need to do something like:
<a4j:commandLink ajaxSingle="true" action="#{gestionCodeLibelle.deleteSelectedItem}" reRender="myTable" eventsQueue="serviceQueue"> <h:graphicImage value="/img/icones/supprimer.png" /> <f:param name="myParam" value="#{some value}"/> </a4j:commandLink>
Also, the
(value="myParam" )
is not necessary as long as the parameter is named the same of the property. @RequestParameter is all you need based on what you have in GestionCodeLibelleAction.
-
3. Re: RequestParameter is null
cash1981 Oct 6, 2010 3:28 AM (in response to tienlantri)My guess is because you are using POST and not GET.
-
4. Re: RequestParameter is null
tienlantri Oct 6, 2010 7:58 AM (in response to tienlantri)Thanks Ray Van.
It works after adding <f:param>
But one more problem is that when I perform add a new item, even I can get myParam from request, I have this error: @Out attribute requires non-null value: gestionCodeLibelle.myParam"
However, I already added @In @Out to my request like this:
@In
@Out
@RequestParameter(value = "myParam")
private String myParam; -
5. Re: RequestParameter is null
rvaneperen Oct 6, 2010 11:35 PM (in response to tienlantri)First of all, I would remove the @In, the @RequestParmeter takes care of the injection. As to why it is not there to @Out, I'm not sure, Can you share the code for your backing bean?
-
6. Re: RequestParameter is null
tienlantri Oct 7, 2010 8:41 AM (in response to tienlantri)It works if I put
@Out(required = falsed)
Anyway, the code is followed
action declared in xhtml
<a4j:commandLink ajaxSingle="true" action="#{gestionCodeLibelle.addNewItem}" reRender="myTable" eventsQueue="serviceQueue"> <h:graphicImage value="/img/icones/enregistrer.png" /> <f:param name="myParam" value="#{myParam}"/> </a4j:commandLink>
It passes to class ACTION
@AutoCreate @Scope(ScopeType.CONVERSATION) @Name("gestionCodeLibelle") public class GestionCodeLibelleAction<T extends AvecLibelle & AvecCode> { @Out @RequestParameter(value = "myParam") private String myParam; @In @Out private T itemToAdd; ... public void addNewItem() { boolean valid = true; /* * check if the adding code is null or already in the list created codes * if yes, notify user if no, add a new one */ valid = validateCode(); if (valid) { entityManager.merge(itemToAdd); myList.add(itemToAdd); initItemToAdd(); // Collections.sort(consignes, new Consigne.ConsigneComparator()); logger.info("item added"); } } private boolean validateCode() { boolean isValid = true; if (itemToAdd.getCode() == null) { isValid = false; FacesMessages.instance().addFromResourceBundle(Severity.ERROR, "code.cannotNull"); } else { if (Util.CONSIGNE_PARAM.equals(myParam)) { if (itemToAdd.getCode().length() != 6) { isValid = false; FacesMessages.instance().addFromResourceBundle( Severity.ERROR, "code.length", Util.CONSIGNE_PARAM, "6"); } } else if (Util.EFTCO_PARAM.equals(myParam)) { if (itemToAdd.getCode().length() != 3) { isValid = false; FacesMessages.instance().addFromResourceBundle( Severity.ERROR, "code.length", Util.EFTCO_PARAM, "3"); } if (!itemToAdd.getCode().matches(Util.EFTCO_CODE_EXP)) { isValid = false; FacesMessages.instance().addFromResourceBundle( Severity.ERROR, "eftco.code.wrongFormat"); } } } if (isValid) { for (T item : myList) { if (item.getCode().equals(itemToAdd.getCode().toUpperCase())) { isValid = false; FacesMessages.instance() .addFromResourceBundle(Severity.ERROR, "code.existed", itemToAdd.getCode()); break; } } } return isValid; }
In the Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "ID", "CODE" }), name = "CONSIGNE") @Entity public class Consigne extends EntiteAvecLibelleLazyLoaded implements Serializable, AvecCode { @Id @SequenceGenerator(name = "generator_consigne", sequenceName = "SEQ_CONSIGNE", initialValue = 0, allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator_consigne") @Column(name = "ID", precision = 19, scale = 0) public long getId() { return id; } public void setId(final long id) { this.id = id; } @Column(name = "CODE", unique = true, nullable = false, length = 6, columnDefinition = "char(6)") @NotNull(message = "#{messages['code.cannotNull']}") @Length(max = 6, message = "#{messages['consigne.code.length']}") public String getCode() { return code; } public void setCode(final String code) { this.code = code.toUpperCase(); }