1

Well, I need send data to another site, but also save this information in a bd at the same time.

My code:

<h:form id="form1">
        <p:panelGrid columns="2">
            <p:outputLabel value="Name:"/>
            <h:outputText id="outName" value="#{controPerson.person.name}" />
            <p:outputLabel value="Tel:"/>
            <h:outputText id="outTel" value="#{controPerson.person.tel}" />
            <p:outputLabel value="Age:"/>
            <h:outputText id="outAge" value="#{controPerson.person.age}" />
            <p:outputLabel value="City:"/>
            <h:outputText id="outCity" value="#{controPerson.person.city}" />

            <p:button value="Send" outcome="http://test.sfa.sep.mx/datos">

                    <f:param name="name" value="#{controPerson.person.name}" />
                    <f:param name="tel" value="#{controPerson.person.tel}" />
                    <c:choose>
                        <c:when test="#{controPerson.person.age < 18}">
                            <f:param name="age" value="minor"/>
                        </c:when>
                         <c:when test="#{controPerson.person.age >= 18}">
                            <f:param name="age" value="adult"/>
                        </c:when>                        
                    </c:choose>

                    <f:param name="city" value="#{controPerson.person.city}" />

            </p:button>
        </p:panelGrid>

p:button does not have 'action' property to call method to save data, and p:commandButton does not have 'outcome' property to pass values.

...any ideas??

thanks.....

user3416943
  • 17
  • 1
  • 5

1 Answers1

0

can you use a redirection?

package web;

import java.io.IOException;
import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

@ManagedBean
@ViewScoped
public class HitAndRunMB implements Serializable{
    private static final long serialVersionUID = 1L;
    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public void saveNameInDB() throws IOException{
        System.out.println("saved "+this.name);
        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        externalContext.redirect("http://www.google.com");
    }
}

xhtml

<?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"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>
<h:body>
    <h:form>
       <h:inputText value="#{hitAndRunMB.name}" />
       <p:commandButton action="#{hitAndRunMB.saveNameInDB}"></p:commandButton>
    </h:form>
</h:body>
</html>

code borrowed from Redirect to external URL in JSF

Community
  • 1
  • 1
Leo
  • 6,480
  • 4
  • 37
  • 52