0

I am using the following code to retrieve URL params into a JavaScript variable.

function getUrlParams() {
  var params = {};
  window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) {
    params[key] = value;
  });
  return params;
}
var vName = getUrlParams()["vName"];

I have to set vName into h:inputText.

document.getElementById("Forid:Fldid").value = vName; // didn't work

I am working on Facelets.

pb2q
  • 54,061
  • 17
  • 135
  • 139
p_anantha
  • 302
  • 1
  • 2
  • 11

1 Answers1

1

Don't do it the hard way. Use <f:viewParam>.

<f:metadata>
    <f:viewParam name="vName" value="#{bean.vName}" />
</f:metadata>
...
<h:form>
    <h:inputText value="#{bean.vName}" />
    ...
</h:form>

with

@ManagedBean
@ViewScoped
public class Bean {

    private String vName;

    // Getter+setter.
}

That's all.

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452