如何使用其他Bean作为输入实例化Javabean以保存计算值
如何填充一个JavaBean,该JavaBean存储使用来自许多其他JavaBean的输入值计算的值,而不使用CodeScope 我正在创建一个JSF应用程序,用户可以在其中对零件系统执行工程计算。My facelet view有一个Primefaces选项卡视图,其中每个零件都有一个选项卡,用户可以在其中输入该零件的规格(材料、宽度、厚度、直径等),然后是一个结果选项卡,其中有一个命令按钮,按下该按钮时,会显示许多执行的工程计算/公式(使用MathJax)并显示其计算值 我已经对所有输入bean进行了编码,并开始尝试填充“结果”选项卡,但我的支持bean中的如何使用其他Bean作为输入实例化Javabean以保存计算值,java,oop,Java,Oop,如何填充一个JavaBean,该JavaBean存储使用来自许多其他JavaBean的输入值计算的值,而不使用CodeScope 我正在创建一个JSF应用程序,用户可以在其中对零件系统执行工程计算。My facelet view有一个Primefaces选项卡视图,其中每个零件都有一个选项卡,用户可以在其中输入该零件的规格(材料、宽度、厚度、直径等),然后是一个结果选项卡,其中有一个命令按钮,按下该按钮时,会显示许多执行的工程计算/公式(使用MathJax)并显示其计算值 我已经对所有输入bea
computersults()
操作的模式开始变得糟糕
下面是简化的模拟代码
@Named("calculator")
@SessionScoped
public class BackingBean
@Inject
JointConfigurationPojo joint; //Parent POJO which groups other POJOs for Serializing just the users inputs
@Inject
JointToleranceResults jTol; // Bean to store computed results related to joint tolerances. I'll have many more types of engineering calcs to perform
@Inject
JointTolEngServices jointTolService; // Contains engineering formulas for computing joint tolerances
public void computeResults() {
jTol.setJoint_stackup_max(jointTolService.computeLengthMax(joint.getPlate1().getMaximum_thickness(), joint.getPlate2().getMaximum_thickness(), joint.getBoltWasher().getMaximum_thickness(), joint.getNutWasher().getMaximum_thickness());
jTol.setJoint_stackup_min(jointTolService.computeLengthMin(joint.getPlate1().getMinimum_thickness(), joint.getPlate2().getMinimum_thickness(), joint.getBoltWasher().getMinimum_thickness(), joint.getNutWasher().getMinimum_thickness());
jTol.setMin_bolt_thread(jointTolService.computeThreadProtrusion(joint.getPlate1().getMinimum_thickness(), joint.getPlate2().getMinimum_thickness(), joint.getBoltWasher().getMinimum_thickness(), joint.getNutWasher().getMinimum_thickness(), joint.getBolt().getBoltShaftLength(), joint.getNut().getNutHeight());
yuk or is this how it's got to be??
}
我有十几个或更多的计算结果bean,这一部分越来越混乱。如何清理ComputersResults()方法??必须有更好的方法来实例化所有的结果bean。。。和建设者?CDI
--
--
也许你应该让你的bean在计算上做更多的工作,如果这不可能,那么你可以将整个bean传递给
jointTolService
应该是这样的:
jointTolService.computeLengthMax(joint);
jointTolService.computeLengthMin(joint);
jointTolService.computeThreadProtrusion(joint)
或者更好
jointTolService.setJoint(joint);
JointToleranceResults result = jointTolService.makeAllCalculation();
而且
jointTolService.makeAllCalculation()
会调用计算方法。无可否认,不漂亮,但是除了你的方法使用了大量的参数之外,我看不出你所做的有什么错。我不知道传递单个参数或我的整个jointConfiguration bean哪个更好。。。。jointTolService.ComputeLength最大值(joint),甚至jointTolService.ComputeLength最大值(joint.getPlate1(),joint.getPlate2()),等等。然后抓住板块的两个厚度属性。我不认为这个问题是JSF独有的。这只是一个问题。在JSF中实现某些重构时,您可能会遇到一些技术困难,但如果出现这种情况,您可以问一个更具体的问题。
public class JointConfigurationPojo implements Serializable { //Could have various number of joint configurations (Tapped hole/weld stud/3plates)
public JointConfigurationPojo () {
bolt = new Bolt();
boltWasher = new Washer();
nutWasher = new Washer();
nut = new Nut();
plate1 = new Plate();
plate2 = new Plate();
}
jointTolService.computeLengthMax(joint);
jointTolService.computeLengthMin(joint);
jointTolService.computeThreadProtrusion(joint)
jointTolService.setJoint(joint);
JointToleranceResults result = jointTolService.makeAllCalculation();