0

I have a project and I decided to make it look better. I learned how to use bootstrap and then tried on some of my pages. Although doing the same things on xhtml pages, some of my pages' buttons does not work correctly. Here is an example from my code

my add function which is being used from interface:

@Override
public void add(Object object) {

    Session session = factory.openSession();

    session.beginTransaction();

    session.save(object);

    session.getTransaction().commit();

    session.close();

}

and i use it like this in my registerpage:

<?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">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                template="/template/site.xhtml"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets">



    <ui:define name="content">
        <h:form> 
            <style>
                .error{color:red}  
            </style>

            <div class="form-group">
                <label for="inputEmail4">Product name</label>
                <h:inputText class="form-control" value="#{product_bean.p_name}" 
                             id="name"
                             required="true"
                             requiredMessage="Product name can't be empty!"
                             >
                    <f:validator validatorId="only_letter_validator"/>
                </h:inputText>
                <h:message for="name" styleClass="error"/> <br></br>
            </div>


            <h:commandButton value="Save" action="#{products_controller.add(product_bean)}">
                <f:actionListener binding="#{products_controller.setFactory()}"/>
            </h:commandButton>

        </h:form>


    </ui:define>
</ui:composition>

my command button is working fine. here is my delete method:

@Override
public void delete(int id) {
    Session session = factory.openSession();
    session.beginTransaction();
    session.createQuery("delete from Product where id=" + id).executeUpdate();
    session.getTransaction().commit();
    session.close();
}

and this is how I use it:

<?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">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"   
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      template="/template/site.xhtml">

    <ui:define name="content">
            <h2><h:outputText value ="Product List"></h:outputText></h2>

            <h:dataTable styleClass="table table-striped" value = "#{products_controller.productsList}" rows="#{products_controller.productsList.size()}" var = "item" border="1" headerClass="tableHeader" > 

                <h:column>
                    <f:facet name="header"> ProductID  </f:facet>
                    <h:outputText value="#{item.p_id}" />
                </h:column>


                <h:column>
                    <f:facet name="header"> Productname </f:facet>
                    <h:outputText value="#{item.p_name}" />
                </h:column>

                <h:column>
                    <f:facet name="header"> Product class </f:facet>
                    <h:outputText value="#{item.p_class}" />
                </h:column>

                <h:column>
                    <f:facet name="header" > Productprice </f:facet>
                    <h:outputText value="#{item.p_price}"  />
                </h:column>

                <h:column>
                    <f:facet name="header"> ProductPP </f:facet>
                    <h:outputText value="#{item.p_property}" />
                </h:column>

                <h:column>
                    <f:facet name="header"> ProductTotal </f:facet>
                    <h:outputText value="#{item.p_total}" />
                </h:column>

            </h:dataTable>  
            <br></br><br></br>

            <div>
            Ürün ID Numarası <h:inputText value="#{deleteID}"
                                              id="id"
                                              required="true"
                                              requiredMessage="Can not be empty!"
                                              validator="#{inputValidators.OnlyLetter}"/>
            <h:message for="id" styleClass="error"/> 
            <h:commandButton value="Delete" action="#{products_controller.delete(deleteID)}">
                <f:actionListener binding="#{products_controller.setFactory()}"/>
            </h:commandButton>
            </div>
    </ui:define>
</ui:composition>

actually I am thinking they are same and it was working before I started to use bootstrap. one is working but other is not. what is different or what should I change? I traced it but could not figure out anything.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

0

i found the solution and saw there are many people strugling with this problem. so i am sharing.

if your commandButtons are not in a <h:form> BUTTONHERE <h:form> they don't work. You can take whole table or just buttons between form parts, they will work.